/*
 *说明：资源账号信息表 首页脚本
 *
 *@author liuxun 2012-03-18
*/

var opeForm;
var localhostGrid;
var pullGrid;

$(function(){
	opeForm = $('#opeForm');

	pullGrid=$('#pullAccTable').datagrid({
		title: '未下拉资源账号',
		frozenColumns:[[
            {title:'选择',field:'ck',checkbox:true}
		]],
		columns:[[

            {title:'未下拉资源账号',field:'rsc_acc',align:'center',width:100}

        ]],
		pagination:false,
		singleSelect: true
	});
	
	localhostGrid=$('#localPullAccTable').datagrid({
		title: '已下拉资源账号',
		frozenColumns:[[]],
		columns:[[

            {title:'已下拉资源账号',field:'rsc_acc',align:'center',width:100}
            
        ]],
		pagination:false,
		singleSelect: false
	});


	$('#clearBtn').click(clearOperation);
	$('#reloadBtn').click(refreshWin);
	$('#registerBtn').click(registerOperation);
	$('#queryPullBtn').click(queryPullOperation);
});

//翻页时自动调用此函数
function onLoadPrev(msg){
	var queryParams=grid.datagrid('options').queryParams;
	queryParams['firstQuery']=false;
}

//查询操作
function queryLocalhostOperation(){
	
	var params = opeForm.serializeObject();
	localhostGrid.datagrid("options").pageNumber = 1;
	localhostGrid.datagrid({
		url: 'C_RSC_ACC!queryList.do',
		queryParams: jQuery.extend({}, params, {'firstQuery': true})
	});
}

// 提取未下拉的资源账号
function queryPullOperation(){
	
	var rsc_id = $('#rsc_id').val();
	
	if(rsc_id == ''){
		showInfoWin('请选择资源！');
		return;
	}		
			
	var params = opeForm.serializeObject();
	pullGrid.datagrid("options").pageNumber = 1;
	pullGrid.datagrid({
		url: 'C_RSC_ACC!queryPullListSelect.do',
		queryParams: jQuery.extend({}, params, {'firstQuery': true})
	});
	
	queryLocalhostOperation();
}

//清空操作（重置）
function clearOperation() {
	opeForm.resetForm();
}

//选择资源
function select_c_rsc() {
	var node_id = $('#node_id').val();
	var action = "C_RSC!showSelect.do?model.rsc_status=01&model.rsc_main_type=01&model.node_id="+node_id;
	var row = showModalWin(action,'A2');
	
	if (row) {
		$('#rsc_id').val(row.rsc_id);
		$('#rsc_name').val(row.rsc_name);
	}
}

//查看明细
function showInfo(key) {
	var url = 'C_RSC_ACC!showInfo.do?model.key=' + key;
	openWin(url,'pop'); 
}

//登记下拉资源账号信息表
function registerOperation(){  
	var rows = pullGrid.datagrid('getSelections');
	if (rows.length == 0) {
		showInfoWin('请您首先选中一条记录!');
		return;
	}  

	if (rows.length > 1) {
		showInfoWin('只能选择一条记录');
      	return; 
	}
	
	var rsc_id = $('#rsc_id').val();
	
	//alert(rsc_id + '----' + rows[0].rsc_acc);

	var url = 'C_RSC_ACC!showEditPull.do?model.rsc_id=' + rsc_id +'&model.rsc_acc=' + rows[0].rsc_acc;
	openWin(url,'pop','A3');
}

//下拉成功后删除未下拉列表中的选择项，刷新本地已下拉列表
function deleteRowsOperation(){
	
	var rows = pullGrid.datagrid('getSelections');
	pullGrid.datagrid('deleteRow', pullGrid.datagrid('getRowIndex',rows[0]));  
	queryLocalhostOperation();
}

//操作成功后刷新列表
function afterOK(){
	queryOperation();
}